package com.bjpowernode.web;

import com.bjpowernode.model.TActivityRemark;
import com.bjpowernode.query.ActivityRemarkQuery;
import com.bjpowernode.result.R;
import com.bjpowernode.service.ActivityRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class ActivityRemarkController {

    @Resource
    private ActivityRemarkService activityRemarkService;

    /**
     * 逻辑删除备注记录
     * @param id id
     * @return R
     */
    @DeleteMapping(value = "/api/activity/remark/{id}")
    public R delActivityRemark(@PathVariable("id") Integer id) {
        int del = activityRemarkService.delActivityRemarkById(id);
        return del >= 1 ? R.OK(): R.FAIL();
    }

    /**
     * 更新备注记录
     * @param activityRemarkQuery activityRemarkQuery
     * @param token token
     * @return R
     */
    @PutMapping(value = "/api/activity/remark")
    public R editActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery, @RequestHeader("Authorization")String token) {
        activityRemarkQuery.setToken(token);
        int update = activityRemarkService.updateActivityRemark(activityRemarkQuery);
        return update >= 0 ? R.OK(): R.FAIL();
    }

    /**
     * 根据id查询备注信息
     * @param id id
     * @return R
     */
    @GetMapping(value = "/api/activity/remark/{id}")
    public R editActivityRemark(@PathVariable("id")Integer id) {
        TActivityRemark activityRemark = activityRemarkService.getActivityRemarkById(id);
        return R.OK(activityRemark);
    }

    /**
     * 查询备注记录列表
     * @param current 当前前
     * @return R
     */
    @GetMapping(value = "/api/activity/remark")
    public R activityRemarkPage(@RequestParam(value = "current", required = false) Integer current, @RequestParam(value = "activityId", required = true) Integer activityId) {
        if (current == null) {
            current = 1;
        }
        ActivityRemarkQuery activityRemarkQuery = new ActivityRemarkQuery();
        activityRemarkQuery.setActivityId(activityId);
        PageInfo<TActivityRemark> pageInfo = activityRemarkService.getActivityRemarkByPage(current, activityRemarkQuery);
        return R.OK(pageInfo);
    }

    /**
     * 市场活动填写备注
     * @param activityRemarkQuery
     * @param token
     * @return
     */
    @PostMapping(value = "/api/activity/remark")
    public R addActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery, @RequestHeader("Authorization")String token) {
        activityRemarkQuery.setToken(token);
        int save = activityRemarkService.saveActivityRemark(activityRemarkQuery);
        return save >= 1 ? R.OK(): R.FAIL();
    }

}
